
#include "stdafx.h"
#include "LoggerImp.h"



namespace woe
{
	LoggerImp::LoggerImp()
		:current_logger_level_(0)
	{

	}

	LoggerImp::~LoggerImp()
	{

	}

	void LoggerImp::setLogLevel(short lvl)
	{
		current_logger_level_ = lvl;
	}


	void LoggerImp::log(short lvl, short label, const string& strMsg)
	{
		TimeStamp ts;

		//
		//	should meet the current log level
		//
		if (lvl>=current_logger_level_)
		{
			for (TargetEntryList::iterator it= target_entrys_.begin();
				it!=target_entrys_.end();
				it++)
			{
				TargetEntry& entry = *it;
				if (entry.meetRequirement(lvl,label))
				{
					entry.target_->doLog(strMsg, LogLevelUtil::getLogLevelName(lvl), ts);
				}
			}
		}
	}


	void LoggerImp::registerTarget(LogTarget* tgt, short lvl, short label)
	{
		target_entrys_.push_back(TargetEntry(lvl, label, tgt));
	}
}